package com.imooc.distributedemo.resume.time;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimleDateFormatDemo {

    /**
     * 使用ThreadLocal定义一个全局的SimpleDateFormat
     */
    private static ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>(){
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };

    public static void main(String[] args) {
        String date = simpleDateFormatThreadLocal.get().format(new Date());
        System.out.println(date);
    }
}
